#!/usr//bin/env python
# _*_ coding: utf-8 _*_
# author:  HeroHu
# time  :  datetime
import os
import json
import sys
import datetime, time

from django.core.management import BaseCommand, CommandError
from django.core.management.base import no_translations
from django.conf import settings

from hony.models import ArticleModels
from unitool.slib.baidu_api import apipushurl


def list_sub(l1: list, l2: list) -> list:
    """"""
    for _ in l2:
        l1.remove(_)
    return l1


class Command(BaseCommand):
    help = "百度seo 站长url地址提交"

    def handle(self, *args, **options):
        host = "https://www.gmclqb.cn"
        qs = ArticleModels.objects.push_baidu_article(reverse=False)
        if not qs.exists():
            raise CommandError("没有待提交的url")

        not_same_sites_urls = []
        not_valid_urls = []
        for q in qs:
            datas = [q.link()]
            res = apipushurl(web_host=host, urls=datas)
            # 更新推送状态
            if 1 == res["success"]:
                q.set_baidu_sign()

            # 缺少推送限额
            if res["remain"] <= 0:
                raise CommandError("当日推送限额已用完")
            elif res["remain"] <= 2000 and res["remain"] > 0:
                step = res["remain"]
            else:
                step = 2000
